// Test.cpp: implementation of the Test class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "Test.h"
#include "FunctionRegister.h"
#include "FunctionObject.h"
#include "part.h"
//#include "PartPropertyDB.h"
#include "..\Command\JointCommand.h"
#include "AutoJointGenerator.h"
#include "joint.h"
#include "joinInfo.h"
#include <PropertyFactory.h>

#include <cppunit/ui/mfc/TestRunner.h>
// CppUnit: TestFactoryRegistry to retreive the top test suite that contains all registered tests.
#include <cppunit/extensions/TestFactoryRegistry.h>
// CppUnit: MFC TestRunner
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif 

#pragma warning( disable : 4786 )
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TestEx::TestEx()
{

}

TestEx::~TestEx()
{

}

void TestEx::Test_Create()
{
	FunctionRegisterInfo* pInfo = NULL;
	ASSERT(GetFunctionRegister().FindInfo(1, pInfo));

	FunctionObject* pObject = pInfo->CreateObject();
	ASSERT(pObject != NULL);
	delete pObject;
}

void TestEx::Test_Fun()
{
	FunctionRegisterInfo* pInfo = NULL;
	ASSERT(GetFunctionRegister().FindInfo(1, pInfo));

	FunctionObject* pObject = pInfo->CreateObject();
	ASSERT(pObject != NULL);

	Part part;
	part.AttachFunction(pObject);
	FunctionObject* pFunction = part.GetFunction(1);
	ASSERT(pFunction != NULL);
	pFunction->Execute();
}

void TestEx::Test_Property()
{
	Part part(_T("D1"));
}

void TestEx::Test_Function()
{
	Part part(_T("L2"));
	Part part1(_T("D1"));
	Part part2(_T("D2"));
}

#include "PartConstructCommand.h"
void TestEx::Test_Joint()
{
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), _T("NWEPDI"));
	ASSERT(pL2);

	PartConstructCommand command(_T("L2.20"), pL2);
	ASSERT(command.Execute());

	Part* pL8 = GetPartGenerator().Generate(_T("L8"), _T("NWEPDI"));
	ASSERT(pL8);

	JointCommand jointcommand(pL2, pL8);
	ASSERT(jointcommand.Execute());

	delete pL2;
	delete pL8;
}


void TestEx::Test_Get_Data()
{
	Part* pL2 = GetPartGenerator().Generate(_T("L2"), _T("NWEPDI"));

	PartConstructCommand command(_T("L2.20"), pL2);
	ASSERT(command.Execute());

	delete pL2;
} 

void TestEx::RunUnitTests()
{
  CPPUNIT_NS::MfcUi::TestRunner runner;
  runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
  runner.run();
}

